/**
 * 批量删除用户
 * @url admin/system/user/sys/batchDelete
 * @description 批量删除用户
 */
module.exports = {
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: '批量删除成功' };
		
		// 业务逻辑开始-----------------------------------------------------------
		let { ids } = data;
		
		if (!ids || !Array.isArray(ids) || ids.length === 0) {
			return { code: -1, msg: '请选择要删除的用户' };
		}
		
		// 不能删除自己
		if (ids.includes(uid)) {
			return { code: -1, msg: '不能删除当前登录用户' };
		}
		
		// 删除用户
		await db.collection('uni-id-users')
			.where({ _id: _.in(ids) })
			.remove();
		
		res.data = {
			deletedCount: ids.length
		};
		
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}

